<--- %%NOBANNER%% --> gotobmark.sas
 BackForward

/*-------------------<-- Start of Description-->---------------------\
| Move the cursor to the bookmark in the last opened word document;  |
|---------------------<-- End of Description-->----------------------|
|--------------------------------------------------------------------|
|------------<-- Start of Files or Arguments Needed-->---------------|
| Argument:                                                          |
|    bmark: the name of the bookmark;                                |
|    insidedata: if you are using this function inside a data step;  |
|                default is False, (this function is used outside    |
|                data step;                                          |
|    wordref: is not necessary, default is "wordsys";                |
|-------------<-- End of Files or Arguments Needed-->----------------|
|--------------------------------------------------------------------|
|------------------<-- Start of Files Created-->---------------------|
| Example: %gotobmark('t1');                                         |
| Usage:   %gotobmark(bmark,insidedata, wordref);                    |
\-------------------<-- End of Files Created-->---------------------*/
%macro gotobmark/parmbuff;;
/*--------------------------------------------\
| Author:   Duo Zhou;                         |
| Created:  2-20-2001 8:58pm;                 |
| Modified: 12-25-2001 4:21pm;                |
| Purpose:  Move the cursor to the bookmark in|
|           the word document;                |
\--------------------------------------------*/
%local arg fref wsid rc;
%let arg=%qscan(&syspbuff,-1,%str((),));
%let fref=; %let wsid=0; %let insidedata=;%let bookmark=;
%if (%index(%quote(%upcase(%sysfunc(compress(%quote(&arg))))),%str(WORDREF=))) or 
    (%index(%quote(%upcase(%sysfunc(compress(%quote(&arg))))),%str(WINREF=))) or 
    (%index(%quote(%upcase(%sysfunc(compress(%quote(&arg))))),%str(WINDOW=))) or
    (%index(%quote(%upcase(%sysfunc(compress(%quote(&arg))))),%str(WIN=)))
      %then %do;
   %let fref=%qscan(&arg, 2, %str(= ));
   %put --> Note: Checking the status of window "&fref" to see if it is opened.;
%end;
%else %if (%words(&syspbuff)>2) %then %do;
   %if not (%index(%quote(%upcase(%sysfunc(compress(%quote(&arg))))),%str(=))) %then %do; 
      %let fref=%sysfunc(compress(&arg));
      %put --> Note: Checking the status of window "&fref" to see if it is open.;
   %end;
   %else %put --> Alert! Keyword Parameter isn%str(%')t declared!;
%end;
%else %if (%words(&syspbuff,dlm=%quote(,()))=2) and ((%quote(%upcase(&arg)) ne %quote(T)) and (%quote(%upcase(&arg)) ne %quote(TRUE))) %then %do;
   %let fref=%sysfunc(compress(&arg));
   %put --> Note: Checking the status of window "&fref" to see if it is opened.;
%end;
%else %if (%words(&syspbuff,dlm=%quote(,()))=2) and ((%quote(%upcase(&arg)) eq %quote(T)) or (%quote(%upcase(&arg)) eq %quote(TRUE))) %then %do;
   %let fref=wordsys;
   %let insidedata=T;
   %put --> Note: Checking the status of window "&fref" to see if it is opened.;
%end;
%else %if (%words(&syspbuff,dlm=%quote(,()))<2) %then %do;
   %let fref=wordsys;
   %put --> Note: No window reference is specified%str(;) Checking the status of the default; 
   %put -->       window "&fref" to see if it is open.;
%end;
%if (&fref ne ) %then %let wsid=%sysfunc(fopen(&fref,o,132,e));
%if &wsid %then %do;
   %let rc=%sysfunc(fclose(&wsid));
   %let bookmark=%qscan(&syspbuff,1,%str(,()''""));
   %if (%quote(%upcase(&insidedata))=%quote(T)) or (%quote(%upcase(&insidedata))=%quote(TRUE)) %then %do;
   file &fref lrecl=2000;
   length str $2000.;
   str='[EditGoTo .Destination = "'||trim(left("&bookmark"))||'"]';
   put str;
%end;
%else %do;
data _null_;
   file &fref lrecl=2000;
   length str $2000.;
   str='[EditGoTo .Destination = "'||trim(left("&bookmark"))||'"]';
   put str;
   run;
   %end;
%end;
%else %put ==> Alert! Incorrect window reference "&fref", or window "&fref" isn%str(%')t open.;
%mend gotobmark;